package com.hsy.leancloudchat.login

import android.content.Intent
import android.os.Bundle
import cn.leancloud.LCUser
import com.hsy.leancloudchat.LeanCloudHelper
import com.hsy.leancloudchat.databinding.ActivityLoginBinding
import com.hsy.leancloudchat.main.MainActivity
import com.hsy.leancloudchat.mvvmUtils.HsyActivity
import com.hsy.leancloudchat.mvvmUtils.HsyViewModel

class LoginActivity : HsyActivity<ActivityLoginBinding, HsyViewModel>() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        mBinding.btnLoginIn.setOnClickListener {
            LeanCloudHelper.getInstance()
                .loginIMByUserNameAndPassword(
                    mBinding.etUserName.text.toString(),
                    mBinding.etPassword.text.toString(),
                    this
                ) {
                    startActivity(Intent(this, MainActivity::class.java))
                    finish()
                }
        }

        mBinding.btnSignUp.setOnClickListener {
            LeanCloudHelper.getInstance()
                .saveUserInBackground(LCUser().apply {
                    username = mBinding.etUserName.text.toString()
                    password = mBinding.etPassword.text.toString()
                }, this)
        }
    }
}